<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">晨检记录</small>
      </a>
      <a class="operation" v-on:click="show = !show" v-show="operation">
        <i class="el-icon-setting"></i> 操作
      </a>
      <a href="javascript:;" class="save" v-show="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
      <!--dialog-->
      <transition name="fade">
        <div class="operatbox" v-show="show">
          <a @click="update()">修改</a>
          <a @click="handleDelete()">删除</a>
        </div>
      </transition>
    </header>
  
    <main>
      <div class="formcontent">
        <ul>
          <li>
            <span><em>*</em>晨检日期</span>
            <div class="froms">
              <label>{{listData.createDate|time}}</label>
            </div>
          </li>
          <li>
            <span><em>*</em>晨检结果</span>
            <div class="froms">
              <el-select v-model="listData.morningRecordContent" placeholder="请选择" :disabled="forbidden">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
            </div>
          </li>
          <li>
            <span><em>*</em>姓名 </span>
            <div class="froms">
              <label>{{listData.enterprisePerson.name}}</label>
            </div>
          </li>
        </ul>
      </div>
    </main>
  </div>
</template>

<script>
  import {
    MorningRecordDelete
  } from '../../api/api';
  import {
    MorningRecordDetail,
    MorningRecordUpdate
  } from '../../api/api';
  export default {
    data() {
      return {
        options: [{
          value: '√',
          label: '正常'
        }, {
          value: '△',
          label: '发热'
        }, {
          value: '⊙',
          label: '腹泻'
        }, {
          value: '﹟',
          label: '皮肤溃疡'
        }, {
          value: '※',
          label: '其他传染病'
        }, {
          value: '不在岗',
          label: '不在岗位'
        }],
        listData: {},
        show: false, //默认隐藏
        operation: true,
        save: false,
        forbidden: true
  
      };
    },
    methods: {
      update: function() {
        this.operation = false,
          this.save = true,
          this.show = false
          this.forbidden = false
      },
      //数据加载方法
      getData() {
        //定义需要传给通讯的参数： unid    
        let options = {
          params: {
            id: this.$route.query.unid,
          }
        }
  
        //调取接口
        MorningRecordDetail(options).then((res) => {
          if (res.success === true) {
            this.listData = res.data;
            // console.log(res.data)
          }
        })
      },
      //删除方法
      handleDelete() {
        let deletParams = {
          params: {
            ids: this.$route.query.unid,
          }
        }
        this.$confirm('是否删除此条信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          MorningRecordDelete(deletParams).then(() => {
            this.getData();
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.$router.go(-1);
          });
        });
      },
      submitForm: function() {
        let varQueryData = {
          Name: this.listData.enterprisePerson.name,
          Unid: this.listData.enterprisePerson.unid,
          //Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,//规范unid
        }
        let data = {
          MorningRecordDate: this.listData.createDate,
          MorningRecordContent: this.listData.morningRecordContent,
          Unid: this.$route.query.unid,
          EnterprisePerson: varQueryData,
        }
        let dataoption = {
          params: {
            Data: JSON.stringify(data),
            UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
          }
        }
        //调取接口
        MorningRecordUpdate(dataoption).then((res) => {
          if (res.success === true) {
            this.$message.success('保存成功');
            this.$router.go(-1);
          } else {
            this.$message.error(res.msg);
          }
        }).catch(function() {
          this.$message.error('网络异常。');
        })
  
      }
  
  
    },
    created() {
      this.getData();
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style lang="scss" scoped>
  
</style>
